package vsvm.gui.menus;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Iterator;

import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;

import vsvm.gui.Environment;
import vsvm.gui.forms.CreateDataSourceDialog;
import vsvm.gui.forms.SelectDataSourceDialog;

public class DataModelMenu implements ActionListener {
	final static String AC_CREATE = "create";

	public void actionPerformed(ActionEvent e) {
		String ac = e.getActionCommand();
		
		if (ac.equals(AC_CREATE)) {
			SelectDataSourceDialog d = new SelectDataSourceDialog(Environment.getEnvironment().getMainFrame());
			d.setVisible(true);
	
		}
	}
	
	
	public static JPopupMenu getPopup() {
		JPopupMenu menu = new JPopupMenu();
		ArrayList<JMenuItem> items = createItems();
		for (Iterator<JMenuItem> iter = items.iterator(); iter.hasNext();) {
			menu.add(iter.next());			
		}
		
		return menu;		
	}
	
	public static ArrayList<JMenuItem> createItems() {
		ArrayList<JMenuItem> arr = new ArrayList<JMenuItem>();
		DataModelMenu dsm = new DataModelMenu();
		
		JMenuItem miCreate = new JMenuItem("Create data model");
		miCreate.setActionCommand(AC_CREATE);
		miCreate.addActionListener(dsm);
		arr.add(miCreate);
		
		return arr;
	}

}
